package org.egedede.osgi.guishell;

import java.awt.event.InputEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JPopupMenu;
import javax.swing.JTree;
import javax.swing.tree.TreePath;

public class BundleTreeCellListener implements MouseListener {

	private JPopupMenu popup;
	private JTree tree;

	public void setTree(JTree tree) {
		this.tree = tree;
	}

	public BundleTreeCellListener() {
		super();
	}

	public void mouseClicked(MouseEvent e) {

	}

	public void mouseEntered(MouseEvent e) {

	}

	public void mouseExited(MouseEvent e) {

	}

	public void mousePressed(MouseEvent e) {
		// FIXME make it work
		TreePath path = tree.getPathForLocation(e.getX(), e.getY());
		System.out.println(path);

		if (path != null) {
			tree.setSelectionPath(path);
			if((e.getModifiers() & InputEvent.BUTTON3_MASK) == InputEvent.BUTTON3_MASK ){
				popup.show(e.getComponent(), e.getX(), e.getY());
			}
		}
	}

	public void mouseReleased(MouseEvent e) {
	}

	public void setPopup(JPopupMenu popup) {
		this.popup = popup;
	}

}
